package com.founder.android.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

/**
 * 数据库使用类
 * @author chen_weihua
 *
 */
public class SampleDBHelper extends DBOpenHelper {

	public SampleDBHelper(Context context) {
		super(context);
	}

	/**
	 * 初始化数据库表结构
	 */
	@Override
	protected void createAllTable(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE IF NOT EXISTS city (" +
				"id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
				"name TEXT, file_name TEXT);");
		runAtVersion2(db);
		
	}

	/**
	 * 初始化数据库表数据
	 */
	@Override
	protected void initializeTableData(SQLiteDatabase db) {
		
	}

	/**
	 * 数据库版本变化
	 */
	@Override
	protected void onDBUpdate(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (oldVersion < 2) {
			runAtVersion2(db);
		}
	}
	
	private void runAtVersion2(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE IF NOT EXISTS location (" +
		"id INTEGER PRIMARY KEY NOT NULL, name TEXT, lat TEXT, lng TEXT);");
	}

}
